<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
    <style>
        html,
        body {
            width: 100%;
            min-height: 100%;
            background: #fff;
        }

        .h10 {
            height: 10px;
            background: #f0f0f0;
        }

        .h1 {
            height: 1px;
            margin-left: 15px;
            background: #f0f0f0;
        }

        .fr {
            float: right;
        }

        .hint {
            color: #666;
            font-size: 12px;
            margin-right: 5px;
        }

        .aui-title {
            color: #fff
        }

        [v-cloak] {
            display: none;
        }

        .presshover {
            background-color: #FAFAFA;
        }

        .wrap {
            background-color: #fff;
            overflow: hidden;
            overflow-y: scroll;
        }

        .aui-chat {
            height: auto;
        }

        .aui-chat .aui-chat-content {
            max-width: 90%;
        }
    </style>
</head>

<body>
    <div class="wrap" id="app">
        <section class="aui-chat clearfix">
            <!-- <div class="aui-chat-header">2016年7月13日</div> -->

            <div v-for="(item,index) in infoList" class="aui-chat-item " :class="myId != item.senderUserId ? 'aui-chat-left' : 'aui-chat-right'">


              <!-- 对方信息 -->
                <div v-if="myId != item.senderUserId">


                  <!-- 如果是有图片两个字 -->
                  <div v-if="item.objectName=='RC:TxtMsg' && item.content.text.split(';')[0]=='图片'">
                      <div class="aui-chat-media">
                          <img src="../../image/liulangnan.png" />
                      </div>
                      <div class="aui-chat-inner">
                          <div class="aui-chat-name">{{senderUserName}}</div>
                          <div class="aui-chat-content" style='background-color:#619be4;'>
                              <div class="aui-chat-arrow"></div>
                              <img :src="item.content.text.split(';')[1]" alt="">
                          </div>
                          <div class="aui-chat-status">
                              <i class="aui-iconfont aui-icon-info aui-text-danger aui-hide"></i>
                          </div>
                      </div>
                  </div>

                  <!-- 如果是没有图片两个字  直接显示文本-->
                  <div v-else>
                      <div class="aui-chat-media">
                          <img src="../../image/liulangnan.png" />
                      </div>
                      <div class="aui-chat-inner">
                          <div class="aui-chat-name">{{senderUserName}}</div>
                          <div class="aui-chat-content" style='background-color:#619be4;'>
                            <div class="aui-chat-arrow"></div>
                            <div v-if="item.objectName=='RC:TxtMsg'" v-html="item.content.text"></div>
                            <div v-else-if="item.objectName=='RC:VcMsg'" @click="to_play_amr(item.content.voicePath)"><img src='../../image/tips/yy_left.png' style='vertical-align: middle;width:20px;margin-right:50px;display:inline-block;' />{{item.content.duration}}s</div>
                          </div>
                          <div class="aui-chat-status">
                              <i class="aui-iconfont aui-icon-info aui-text-danger aui-hide"></i>
                          </div>
                      </div>
                  </div>


                </div>



                <!-- 我方信息 -->
                <div v-else>

                    <!-- 如果是有图片两个字 -->
                    <div v-if="item.objectName=='RC:TxtMsg' && item.content.text.split(';')[0]=='图片'">

                        <div class="aui-chat-media">
                            <img src="../../image/liulangnan.png" />
                        </div>
                        <div class="aui-chat-inner">
                            <div class="aui-chat-name">{{userName}}</div>
                            <div class="aui-chat-content" style='background-color:#619be4;'>
                                <div class="aui-chat-arrow"></div>
                                <img :src="item.content.text.split(';')[1]" alt="">
                            </div>
                            <div class="aui-chat-status">
                                <i class="aui-iconfont aui-icon-info aui-text-danger aui-hide"></i>
                            </div>
                        </div>
                    </div>

                    <!-- 如果是没有图片两个字  直接显示文本-->
                    <div v-else>
                        <div class="aui-chat-media">
                            <img src="../../image/liulangnan.png" />
                        </div>
                        <div class="aui-chat-inner">
                            <div class="aui-chat-name">{{userName}}</div>
                            <div class="aui-chat-content" style='background-color:#619be4;'>
                                <div class="aui-chat-arrow"></div>
                                <div v-if="item.objectName=='RC:TxtMsg'" v-html="item.content.text"></div>
                                <div v-else-if="item.objectName=='RC:VcMsg'" @click="to_play_amr(item.content.voicePath)">{{item.content.duration}}s<img src='../../image/tips/yy_right.png' style='vertical-align: middle;width:20px;margin-left:50px;display:inline-block;' /></div>
                            </div>
                            <div class="aui-chat-status">
                                <i class="aui-iconfont aui-icon-info aui-text-danger aui-hide"></i>
                            </div>
                        </div>
                    </div>


                </div>

            </div>

        </section>
    </div>
</body>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    function openCloseBack() {
        api.closeWin();

    }

    function apiready() {
        var header_top = $api.byId('header_top');
        var header_topPos = $api.offset(header_top);
        $api.fixStatusBar(header_top);

        //获取对方的消息
        var rong;
        var rong_user = {
            userid: 0,
            username: ''
        }

        var isConnetced;
        rong = api.require('rongCloud2');
        //初始化
        rong.init(function(ret, err) {
            if (ret.status == 'success') {


                isConnetced = true;

                var app = new Vue({
                    el: '#app',
                    data: {
                        infoList: [],
                        mymsgList: [],
                        sendUserInfo: [{
                            userId: 0,
                            username: '',
                            portrait: ''
                        }],
                        page: 1,
                        totalpage: 0,
                        myId: 0,
                        senderUserName: api.pageParam.name,
                        userName: $api.getStorage('data').nickname
                    },
                    created: function() {

                        this.myId = $api.getStorage('data').userid

                    },
                    mounted: function() {




                        var $this = this;

                        // 监听最新的消息
                        rong.setOnReceiveMessageListener(function(ret, err) {
                            $this.infoList.push(ret.result.message);
                        })

                        rong.connect({
                            token: $api.getStorage('rong-token')
                        }, function(ret, err) {

                            if (ret.status == 'success') {

                                rong.clearMessagesUnreadStatus({
                                    conversationType: api.pageParam.chat_type,
                                    targetId: api.pageParam.id
                                }, function(ret, err) {

                                })

                                //获取对话最新信息
                                rong.getLatestMessages({
                                    conversationType: api.pageParam.chat_type,
                                    targetId: api.pageParam.id,
                                    count: 20
                                }, function(ret, err) {

                                    if (ret.status == 'success') {

                                        $this.infoList = ret.result;
                                        $this.infoList = $this.infoList.reverse();
                                        $this.$nextTick(function () {
                                          //获取聊天列表高度
                                          var listH = $('.aui-chat').height();
                                          var wrapH = $('.wrap').height();

                                          //点击输入框  聊天列表显示最后一条
                                          var top_new = listH - wrapH;

                                          $('.wrap').scrollTop(top_new);
                                        })

                                    } else {
                                        api.alert({
                                            msg: '最新消息获取错误，请重新打开'
                                        });

                                    }

                                })

                                //对话列表

                            } else {
                                api.alert({
                                    msg: "fdsfdsfds" + JSON.stringify(err)
                                });
                            }
                        })


                    }
                });


            } else {
                api.toast({
                    msg: err.code
                });
            }
        });

        //表情包名称数组
        var imgs = [];
        var imgName = [];

        //添加聊天输入框
        var UIChatTools = api.require('UIChatTools');
        UIChatTools.open({
            chatBox: {
                placeholder: '输入内容', //（可选项）字符串类型；占位提示文本，不传则无占位符
                autoFocuse: false, //（可选项）布尔类型；是否在打开时自动获取焦点，并弹出键盘；默认：false
                maxRows: 6 //（可选项）数字类型；显示的最大行数（高度自适应），超过最大行数则可上下滚动查看；默认：6
            },
            styles: {
                bgColor: '#cccccc',
                margin: 10,
            },
            tools: {
                h: 40,
                iconSize: 30,
                recorder: {
                    normal: 'fs://UIChatTolls/recorder.png',
                    selected: 'fs://UIChatTolls/recorder1.png'
                },
                image: {
                    normal: 'fs://UIChatTolls/image.png',
                    selected: 'fs://UIChatTolls/image1.png'
                },
                video: {
                    normal: 'fs://UIChatTolls/video.png',
                    selected: 'fs://UIChatTolls/video1.png'
                },
                face: {
                    normal: 'fs://UIChatTolls/face.png',
                    selected: 'fs://UIChatTolls/face1.png'
                },
                append: {
                    normal: 'fs://UIChatTolls/append.png',
                    selected: 'fs://UIChatTolls/append1.png'
                }
            },
            emotions: ['widget://res/emotions/basic', 'widget://res/emotions/append1', 'widget://res/emotions/append2']
        }, function(ret) {
            if (ret) {


                if (ret.eventType == 'send') {

                    if (ret.msg == undefined || ret.msg == "") {
                        api.alert({
                            msg: '请输入内容'
                        })
                    } else {

                        if (imgs.length != 0) {
                            UIChatTools.closeBoard();

                            for (var j = 0; j < imgs.length; j++) {
                                var path = "<img style='display:inline-block;width:20px;vertical-align: middle;' src='../../res/emotions/basic/" + imgs[j] + ".png' />";

                                ret.msg = ret.msg.replace(imgName[j], path);

                                var new_html =
                                    "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' ><div class='aui-chat-arrow'></div>" +
                                    ret.msg + "</div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";
                            }

                        } else {
                            var new_html =
                                "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' ><div class='aui-chat-arrow'></div>" +
                                ret.msg + "</div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";
                        }

                        $('.aui-chat').append(new_html);
                        imgs = [];
                        imgName = [];

                        //获取聊天列表高度
                        var listH = $('.aui-chat').height();
                        var wrapH = $('.wrap').height();

                        //点击输入框  聊天列表显示最后一条
                        var top_new = listH - wrapH;

                        $('.wrap').scrollTop(top_new);

                        sengTxtMsg(ret.msg);
                    }
                    UIChatTools.clearText();


                }
            }
        });


        //监听输入框的状态

        var frmH = api.frameHeight; //当前frame的高度
        var first_input = false; //是否第一次点击输入框


        UIChatTools.chatBoxListener({
            name: 'move'
        }, function(ret) {

            if (!first_input) {
                frmH = frmH + 20;

                first_input = true;
            }

            //设定wrap 的高度
            var wrapH = frmH - ret.chatBoxHeight - ret.panelHeight;
            $('.wrap').css('height', wrapH);
            move_h = ret.chatBoxHeight + ret.panelHeight;

            //获取聊天列表高度
            var listH = $('.aui-chat').height();

            //点击输入框  聊天列表显示最后一条
            var top_num = listH - wrapH;
            $('.wrap').scrollTop(top_num);

        });
        UIChatTools.chatBoxListener({
            name: 'change'
        }, function(ret) {

            //设定wrap 的高度
            var wrapH = frmH - ret.chatBoxHeight - ret.panelHeight;
            $('.wrap').css('height', wrapH);
            change_h = ret.chatBoxHeight + ret.panelHeight;

            //获取聊天列表高度
            var listH = $('.aui-chat').height();

            //点击输入框  聊天列表显示最后一条
            var top_num = listH - wrapH;
            $('.wrap').scrollTop(top_num);

        });

        // 表情监听
        UIChatTools.faceListener({
            name: 'face'
        }, function(ret) {
            var click_txt = ret.text;

            api.readFile({
                path: 'widget://image/emotion/emotion.json'
            }, function(ret, err) {
                if (ret) {
                    var new_json = JSON.parse(ret.data);
                    for (var i = 0; i < new_json.length; i++) {
                        if (new_json[i].text == click_txt) {
                            imgs.push(new_json[i].name);
                            imgName.push(new_json[i].text);
                        }
                    }

                }
            });

        });


        // 图片监听
        UIChatTools.imageListener(function(ret) {
            //相册
            if (ret.eventType == 'album') {

                api.getPicture({
                    sourceType: 'library',
                    encodingType: 'png',
                    mediaValue: 'pic',
                    destinationType: 'url',
                    allowEdit: true,
                    quality: 100,
                    saveToPhotoAlbum: false
                }, function(ret, err) {
                    if (ret) {
                        //  console.log("从本地选择图片成功 --- "+JSON.stringify(ret));
                        UIChatTools.closeBoard();

                        var new_html =
                            "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' ><div class='aui-chat-arrow'></div>" +
                            "" + "<img src='" + ret.data + "' /></div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";

                        $('.aui-chat').append(new_html);

                        rong.sendImageMessage({
                            conversationType: api.pageParam.chat_type,
                            targetId: api.pageParam.id,
                            imagePath: ret.data,
                            extra: ''
                        }, function(ret, err) {
                            console.log('从相册选择图片' + JSON.stringify(ret));
                            if (ret.status == 'prepare') {

                            } else if (ret.status == 'progress') {

                            } else if (ret.status == 'success') {
                                console.log('从相册选择图片发送成功');
                            } else if (ret.status == 'error') {
                                console.log('从相册选择图片发送失败');
                            }
                        });

                    } else {
                        console.log("从相册选择图片 --- " + JSON.stringify(err));
                    }
                });


            }

            //点击了编辑
            if (ret.eventType == 'edit') {
                // console.log('点击了编辑');
                api.alert({
                    msg: '还未编写该页面'
                });
            }


            //图片发送按钮
            var img_txt = "图片;";
            if (ret.eventType == "send" && ret.images.length != 0) {
                UIChatTools.closeBoard();
                for (var i = 0; i < ret.images.length; i++) {
                    var new_html =
                        "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' ><div class='aui-chat-arrow'></div>" +
                        "" + "<img src='" + ret.images[i] + "' /></div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";

                    $('.aui-chat').append(new_html);


                    (function(){
                      var x = i;
                      api.ajax({
                          method:"post",
                          url:window.Url.addPicture,
                             data: {
                               files: {file: ret.images[i]}
                             }

                      },function(ret,err){
                        console.log(img_txt);
                          if(ret){
                            if(ret.error == '0')
                            {
                              console.log('qingqiuchenggong de ----'+ret.url);
                              img_txt += (ret.url);
                              sengTxtMsg(img_txt);
                            }
                            else{
                              // api.alert({msg:ret.message});
                            }
                            console.log("图片返回"+JSON.stringify(ret))
                          }else{
                              api.toast({
                                msg : '你没有选择图片',
                                location : 'middle'
                              })
                          }
                      })
                    })()
                }
            }
        });



        //监听 talkback 按钮
        UIChatTools.recorderListener(function(ret) {




            //第一个按钮
            if (ret.eventType == 'press' && ret.target == 'talkback') {
                console.log('按下录音');
                UIChatTools.startTimer();
                api.startRecord({});

            }


            //选择试听
            if (ret.eventType == 'auditionTouchOn') {
                //停止录音
                api.stopRecord(function(ret, err) {
                    if (ret) {
                        path = ret.path;
                        duration = ret.duration;

                        api.startPlay({
                            path: path
                        }, function(ret, err) {
                            if (ret) {
                                console.log('播放完成');
                            } else {
                                console.log(JSON.stringify(err));
                            }
                        });

                    }
                });
            }


            //第2个按钮
            if (ret.eventType == 'start' && ret.target == 'record') {
                UIChatTools.startTimer();
                api.startRecord({});
            }
            else if(ret.eventType=="stop" && ret.target == 'record' ){
              console.log('点点击了第二个按钮----停止了');
            }



            // 发送音频
            if (ret.eventType == 'send' && ret.target == 'talkback') {
              var path1;
              var duration1;
                console.log('发送录音');

                api.stopRecord(function(ret, err) {
                    if (ret) {

                        console.log('这里是停止录音' + JSON.stringify(ret));
                        path = ret.path;
                        duration = ret.duration;


                        var video_box_width = parseInt(duration); //定义气泡的宽度
                        if (video_box_width == 1) { //如果是1s宽度为50px
                            video_box_width = 50;
                        } else if (video_box_width <= 20) { //如果是小于等于20秒气泡的宽度度为时长乘上10加上50px
                            video_box_width = (video_box_width * 10 + 50);
                        } else { //最大气泡宽度为250px
                            video_box_width = 250;
                        }
                        /* 气泡加上数据的html代码 */
                        var redio_html =
                            "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' onclick='to_play_amr(\"" +
                            path + "\")'><div class='aui-chat-arrow'></div>" +
                            duration +
                            "s<img src='../../image/tips/yy_right.png' style='vertical-align: middle;width:20px;margin-left:50px;display:inline-block;'/></div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";


                        $('.aui-chat').append(redio_html);

                        //获取聊天列表高度
                        // var liH = $('.aui-chat-item').height();
                        var listH = $('.aui-chat').height();
                        var wrapH = $('.wrap').height();

                        //点击输入框  聊天列表显示最后一条
                        var top_new = listH - wrapH;

                        $('.wrap').scrollTop(top_new);


                        rong.sendVoiceMessage({
                            conversationType: api.pageParam.chat_type,
                            targetId: api.pageParam.id,
                            voicePath: path,
                            duration: duration,
                            extra: ''
                        }, function(ret, err) {

                            if (ret.status == 'prepare')

                                console.log('语音准备发送');
                            else if (ret.status == 'success')

                                console.log('语音消息发送成功');
                            else if (ret.status == 'error')

                                console.log('语音消息发送失败');
                        });


                    }
                });
            }


            else if( ret.eventType == 'send' && ret.target == 'record' ){
              var path2;
              var duration2;

              api.stopRecord(function(ret, err) {
                  console.log('录音发送失败的返回参数 --- '+JSON.stringify(ret));
                  if (ret) {
                      console.log('这里是停止录音222' + JSON.stringify(ret));
                      path2 = ret.path;
                      duration2 = ret.duration;

                      /* 气泡加上数据的html代码 */
                      var redio_html =
                          "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' onclick='to_play_amr(\"" +
                          path2 + "\")'><div class='aui-chat-arrow'></div>" +
                          duration2 +
                          "s<img src='../../image/tips/yy_right.png' style='vertical-align: middle;width:20px;margin-left:50px;display:inline-block;'/></div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";


                      $('.aui-chat').append(redio_html);

                      //获取聊天列表高度
                      // var liH = $('.aui-chat-item').height();
                      var listH = $('.aui-chat').height();
                      var wrapH = $('.wrap').height();
                      //点击输入框  聊天列表显示最后一条
                      var top_new = listH - wrapH;
                      $('.wrap').scrollTop(top_new);

                      rong.sendVoiceMessage({
                          conversationType: api.pageParam.chat_type,
                          targetId: api.pageParam.id,
                          voicePath: path2,
                          duration: duration2,
                          extra: ''
                      }, function(ret, err) {

                          if (ret.status == 'prepare')
                              console.log('语音准备发送222');
                          else if (ret.status == 'success')

                              console.log('语音消息发送成功222');
                          else if (ret.status == 'error')

                              console.log('语音消息发送失败22'+err.code);
                      });

                  }
              });

            }

        });


        //监听各种事件
        var img_txt2="图片;";
        UIChatTools.toolsListener(function(ret) {
            if (ret.eventType == 'video') {

                api.getPicture({
                    sourceType: 'camera',
                    encodingType: 'png',
                    mediaValue: 'pic',
                    destinationType: 'url',
                    allowEdit: true,
                    quality: 100,
                    saveToPhotoAlbum: false
                }, function(ret, err) {
                    if (ret) {
                        //  console.log("从本地选择图片成功 --- "+JSON.stringify(ret));
                        UIChatTools.closeBoard();

                        var new_html =
                            "<div class='aui-chat-item aui-chat-right'><div class='aui-chat-media'><img src='../../image/liulangnan.png' /></div><div class='aui-chat-inner'><div class='aui-chat-name'>"+$api.getStorage('data').nickname+"</div><div class='aui-chat-content' style='background-color:#619be4;' ><div class='aui-chat-arrow'></div>" +
                            "" + "<img src='" + ret.data + "' /></div><div class='aui-chat-status'><i class='aui-iconfont aui-icon-info aui-text-danger aui-hide'></i></div></div></div>";

                        $('.aui-chat').append(new_html);

                        api.ajax({
                            method:"post",
                            url:window.Url.addPicture,
                               data: {
                                 files: {file: ret.data}
                               }

                        },function(ret,err){
                            if(ret){
                              if(ret.error == '0')
                              {
                                console.log('qingqiuchenggong de ----'+ret.url);
                                img_txt2 += (ret.url);
                                sengTxtMsg(img_txt2);
                              }
                              else{
                                // api.alert({msg:ret.message});
                              }
                              console.log("图片返回"+JSON.stringify(ret))
                            }else{
                                api.toast({
                                  msg : '你没有选择图片',
                                  location : 'middle'
                                })
                            }
                        })


                    } else {
                        console.log("拍照发送失败22 --- " + JSON.stringify(err));
                    }
                });


            } else if (ret.eventType == 'append') {
                console.log('附加按钮');
            }
        });


        UIChatTools.setAppendButton({
            styles: {
                row: 2,
                column: 4,
                iconSize: 50,
                titleSize: 15,
                titleColor: '#000'
            },
            buttons: [{
                normal: 'widget://image/tips/loc1.png',
                highlight: 'widget://image/tips/loc2.png',
                title: '定位'
            }]
        }, function(ret) {
            api.toast({
                msg: '该功能暂未开通',
                duration: 2000,
                location: 'bottom'
            });
        });






        // 加入群聊
        if (api.pageParam.chat_type == "GROUP") {

          console.log('加入群聊----'+api.pageParam.name)


            rong.joinGroup({
                groupId: api.pageParam.id,
                groupName: api.pageParam.name
            }, function(ret, err) {
                if (ret.status == 'success') {
                    // api.toast({ msg: JSON.stringify(ret.status) });
                    console.log('加入群聊成功' + JSON.stringify(ret.status));
                } else {
                    api.toast({
                        msg: err.code
                    });
                }

            })
        }



        // 发送文本消息
        function sengTxtMsg(p) {

            if (isConnetced) {

                var para;
                rong.sendTextMessage({
                    conversationType: api.pageParam.chat_type,
                    targetId: api.pageParam.id,
                    text: p,
                    extra: ''
                }, function(ret, err) {
                    if (ret) {
                        console.log('消息发送成功' + JSON.stringify(ret));
                    } else {
                        console.log('消息发送失败' + JSON.stringify(err));
                    }

                    //
                });
            } else {
                api.alert({
                    msg: "未连接到服务器"
                });
            }
        }



    }



    // 播放发送的音频文件
    function to_play_amr(path) {
        console.log(path);
        api.startPlay({
            path: path
        }, function(ret, err) {
            if (ret) {
                console.log('播放完成');
            } else {
                console.log(JSON.stringify(err));
            }
        });
    }
</script>

</html>
